﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using bomberbide_network;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace bomberbide_client
{
    class gameManager
    {
        #region properties
        private typeCase[,] _Map;
        public typeCase[,] Map
        {
            get { return _Map; }
            set { _Map = value; }
        }

        private List<cActeur> _Acteurs;
        public List<cActeur> Acteurs
        {
            get { return _Acteurs; }
            set { _Acteurs = value; }
        }

        private List<cBuff> _Buffs;
        public List<cBuff> Buffs
        {
            get { return _Buffs; }
            set { _Buffs = value; }
        }

        private ContentManager _Content;
        public ContentManager Content
        {
            get { return _Content; }
            set { _Content = value; }
        }

        private camera _Camera;
        public camera Camera
        {
            get { return _Camera; }
            set { _Camera = value; }
        }

        private Texture2D _Pierre;
        public Texture2D Pierre
        {
            get { return _Pierre; }
            set { _Pierre = value; }
        }

        private Texture2D _Mur;
        public Texture2D Mur
        {
            get { return _Mur; }
            set { _Mur = value; }
        }

        private Texture2D _Grosmur;
        public Texture2D Grosmur
        {
            get { return _Grosmur; }
            set { _Grosmur = value; }
        }

        private Texture2D _Sol;
        public Texture2D Sol
        {
            get { return _Sol; }
            set { _Sol = value; }
        }
        #endregion

        public void Update(GameTime gameTime)
        {
            foreach (cActeur item in this.Acteurs)
            {
                item.Position.X += item.Vitesse.X;
                item.Position.Y += item.Vitesse.Y;
            }
        }

        public void Draw()
        {
            #region dessin map
            for (int i = 0; i < 15; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    switch (this.Map[i, j])
                    {
                        case typeCase.sol:
                            this.Camera.Draw(this.Sol, new Rectangle(64 * i, 64 * j, 64, 64), Color.White);
                            break;
                        case typeCase.mur:
                            this.Camera.Draw(this.Mur, new Rectangle(64 * i, 64 * j, 64, 64), Color.White);
                            break;
                        case typeCase.grosmur:
                            this.Camera.Draw(this.Grosmur, new Rectangle(64 * i, 64 * j, 64, 64), Color.White);
                            break;
                        case typeCase.incassable:
                            this.Camera.Draw(this.Pierre, new Rectangle(64 * i, 64 * j, 64, 64), Color.White);
                            break;
                        default:
                            break;
                    }
                }
            }
            #endregion
            #region dessin acteurs
            foreach (cActeur item in this.Acteurs)
            {
                this.Camera.Draw(item.Texture, new Rectangle((int)item.Position.X, (int)item.Position.Y, 64, 64), Color.White);
            }
            #endregion
        }

        public gameManager(camera Camera, ContentManager Content)
        {
            this._Grosmur = Content.Load<Texture2D>("tiles/grosmur");
            this.Mur = Content.Load<Texture2D>("tiles/mur");
            this.Sol = Content.Load<Texture2D>("tiles/sol");
            this.Pierre = Content.Load<Texture2D>("tiles/pierre");
            this.Camera = Camera;
            this.Acteurs = new List<cActeur>();
            this.Buffs = new List<cBuff>();
            this.Map = new typeCase[15, 13];
            for (int i = 0; i < 15; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    this.Map[i, j] = typeCase.sol;
                }
            }
        }
    }
}
